{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9b22f352-3131-424e-871c-f01074a87813",
   "metadata": {},
   "source": [
    "# 使用缩进来表示代码块，不需要使用大括号 {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f6da61a4-ea5a-4172-a643-ba6342c77807",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "if True:\n",
    "    print('True')\n",
    "    print('True')\n",
    "else:\n",
    "    print('False')\n",
    "    print('False')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8cbbbd2f-2282-4701-b960-14e35abdeb7e",
   "metadata": {},
   "source": [
    "# 如果语句很长，我们可以使用反斜杠 \\ 来实现多行语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "04e491c3-c03e-4688-a1dd-743de2ab010b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'123'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "item_one = '1'\n",
    "item_two = '2'\n",
    "item_three = '3'\n",
    "total = item_one + \\\n",
    "        item_two + \\\n",
    "        item_three\n",
    "total"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7239b97d-e81e-4e38-b1a8-ee232cd25bfe",
   "metadata": {},
   "source": [
    "# 等待用户输入 input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "64c518fe-b259-45c7-829c-5e46a5d6a951",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "按下 enter 键后退出。 \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input(\"\\n\\n按下 enter 键后退出。\")   # \\n\\n 在结果输出前会输出两个新的空行"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48cfc03b-63d1-49da-a600-d34f9d7c40ce",
   "metadata": {},
   "source": [
    "# 同一行中使用多条语句，语句之间使用分号 ; 分割"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "212d47ae-cf99-4fc0-b9d9-e22e4fdfcd7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "runoob\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 脚本执行以上代码，输出结果为 runoob\n",
    "# 交互式命令行执行, 输出结果如下，此处的 7 表示字符数，runoob 有 6 个字符，\\n 表示一个字符，加起来 7 个字符\n",
    "import sys; x = 'runoob'; sys.stdout.write(x + '\\n')   "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "321467be-7db2-4106-9142-aff2052a7251",
   "metadata": {},
   "source": [
    "# print 输出，实现不换行需要在变量末尾加上 end=\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c4967561-99e5-4ac0-afa1-6debaa7a4d9d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12"
     ]
    }
   ],
   "source": [
    "print(1, end='')\n",
    "print(2, end='')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
